/*
* Copyright 2001-2005 Stephen Colebourne
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.joda.time;
import java.util.Locale;
import java.util.TimeZone;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.joda.time.chrono.BuddhistChronology;
import org.joda.time.chrono.GJChronology;
import org.joda.time.chrono.ISOChronology;
import org.joda.time.convert.ConverterManager;
import org.joda.time.convert.IntervalConverter;
/**
* This class is a JUnit test for Interval.
*
* @author Stephen Colebourne
*/
public class TestMutableInterval_Constructors extends TestCase {
// Test in 2002/03 as time zones are more well known
// (before the late 90's they were all over the place)
private static final DateTimeZone PARIS = DateTimeZone.forID("Europe/Paris");
private static final DateTimeZone LONDON = DateTimeZone.forID("Europe/London");
long y2002days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 +
366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 +
365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 +
366 + 365;
long y2003days = 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 +
366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 +
365 + 365 + 366 + 365 + 365 + 365 + 366 + 365 + 365 + 365 +
366 + 365 + 365;
// 2002-06-09
private long TEST_TIME_NOW =
(y2002days + 31L + 28L + 31L + 30L + 31L + 9L -1L) * DateTimeConstants.MILLIS_PER_DAY;
// 2002-04-05
private long TEST_TIME1 =
(y2002days + 31L + 28L + 31L + 5L -1L) * DateTimeConstants.MILLIS_PER_DAY
+ 12L * DateTimeConstants.MILLIS_PER_HOUR
+ 24L * DateTimeConstants.MILLIS_PER_MINUTE;
// 2003-05-06
private long TEST_TIME2 =
(y2003days + 31L + 28L + 31L + 30L + 6L -1L) * DateTimeConstants.MILLIS_PER_DAY
+ 14L * DateTimeConstants.MILLIS_PER_HOUR
+ 28L * DateTimeConstants.MILLIS_PER_MINUTE;
private DateTimeZone originalDateTimeZone = null;
private TimeZone originalTimeZone = null;
private Locale originalLocale = null;
public static void main(String[] args) {
junit.textui.TestRunner.run(suite());
}
public static TestSuite suite() {
return new TestSuite(TestMutableInterval_Constructors.class);
}
public TestMutableInterval_Constructors(String name) {
super(name);
}
protected void setUp() throws Exception {
DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
originalDateTimeZone = DateTimeZone.getDefault();
originalTimeZone = TimeZone.getDefault();
originalLocale = Locale.getDefault();
DateTimeZone.setDefault(PARIS);
TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
Locale.setDefault(Locale.UK);
}
protected void tearDown() throws Exception {
DateTimeUtils.setCurrentMillisSystem();
DateTimeZone.setDefault(originalDateTimeZone);
TimeZone.setDefault(originalTimeZone);
Locale.setDefault(originalLocale);
originalDateTimeZone = null;
originalTimeZone = null;
originalLocale = null;
}
//-----------------------------------------------------------------------
public void testTest() {
assertEquals("2002-06-09T00:00:00.000Z", new Instant(TEST_TIME_NOW).toString());
assertEquals("2002-04-05T12:24:00.000Z", new Instant(TEST_TIME1).toString());
assertEquals("2003-05-06T14:28:00.000Z", new Instant(TEST_TIME2).toString());
}
//-----------------------------------------------------------------------
public void testParse_noFormatter() throws Throwable {
DateTime start = new DateTime(2010, 6, 30, 12, 30, ISOChronology.getInstance(PARIS));
DateTime end = new DateTime(2010, 7, 1, 14, 30, ISOChronology.getInstance(PARIS));
assertEquals(new MutableInterval(start, end), MutableInterval.parse("2010-06-30T12:30/2010-07-01T14:30"));
assertEquals(new MutableInterval(start, end), MutableInterval.parse("2010-06-30T12:30/P1DT2H"));
assertEquals(new MutableInterval(start, end), MutableInterval.parse("P1DT2H/2010-07-01T14:30"));
}
//-----------------------------------------------------------------------
public void testConstructor() throws Throwable {
MutableInterval test = new MutableInterval();
assertEquals(0L, test.getStartMillis());
assertEquals(0L, test.getEndMillis());
}
//-----------------------------------------------------------------------
public void testConstructor_long_long1() throws Throwable {
DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
MutableInterval test = new MutableInterval(dt1.getMillis(), dt2.getMillis());
assertEquals(dt1.getMillis(), test.getStartMillis());
assertEquals(dt2.getMillis(), test.getEndMillis());
assertEquals(ISOChronology.getInstance(), test.getChronology());
}
public void testConstructor_long_long2() throws Throwable {
DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
MutableInterval test = new MutableInterval(dt1.getMillis(), dt1.getMillis());
assertEquals(dt1.getMillis(), test.getStartMillis());
assertEquals(dt1.getMillis(), test.getEndMillis());
assertEquals(ISOChronology.getInstance(), test.getChronology());
}
public void testConstructor_long_long3() throws Throwable {
DateTime dt1 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
DateTime dt2 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
try {
new MutableInterval(dt1.getMillis(), dt2.getMillis());
fail();
} catch (IllegalArgumentException ex) {}
}
//-----------------------------------------------------------------------
public void testConstructor_long_long_Chronology1() throws Throwable {
DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
MutableInterval test = new MutableInterval(dt1.getMillis(), dt2.getMillis(), GJChronology.getInstance());
assertEquals(dt1.getMillis(), test.getStartMillis());
assertEquals(dt2.getMillis(), test.getEndMillis());
assertEquals(GJChronology.getInstance(), test.getChronology());
}
public void testConstructor_long_long_Chronology2() throws Throwable {
DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
MutableInterval test = new MutableInterval(dt1.getMillis(), dt2.getMillis(), null);
assertEquals(dt1.getMillis(), test.getStartMillis());
assertEquals(dt2.getMillis(), test.getEndMillis());
assertEquals(ISOChronology.getInstance(), test.getChronology());
}
//-----------------------------------------------------------------------
public void testConstructor_RI_RI1() throws Throwable {
DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
MutableInterval test = new MutableInterval(dt1, dt2);
assertEquals(dt1.getMillis(), test.getStartMillis());
assertEquals(dt2.getMillis(), test.getEndMillis());
}
public void testConstructor_RI_RI2() throws Throwable {
Instant dt1 = new Instant(new DateTime(2004, 6, 9, 0, 0, 0, 0));
Instant dt2 = new Instant(new DateTime(2005, 7, 10, 1, 1, 1, 1));
MutableInterval test = new MutableInterval(dt1, dt2);
assertEquals(dt1.getMillis(), test.getStartMillis());
assertEquals(dt2.getMillis(), test.getEndMillis());
}
public void testConstructor_RI_RI3() throws Throwable {
MutableInterval test = new MutableInterval((ReadableInstant) null, (ReadableInstant) null);
assertEquals(TEST_TIME_NOW, test.getStartMillis());
assertEquals(TEST_TIME_NOW, test.getEndMillis());
}
public void testConstructor_RI_RI4() throws Throwable {
DateTime dt1 = new DateTime(2000, 6, 9, 0, 0, 0, 0);
MutableInterval test = new MutableInterval(dt1, (ReadableInstant) null);
assertEquals(dt1.getMillis(), test.getStartMillis());
assertEquals(TEST_TIME_NOW, test.getEndMillis());
}
public void testConstructor_RI_RI5() throws Throwable {
DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
MutableInterval test = new MutableInterval((ReadableInstant) null, dt2);
assertEquals(TEST_TIME_NOW, test.getStartMillis());
assertEquals(dt2.getMillis(), test.getEndMillis());
}
public void testConstructor_RI_RI6() throws Throwable {
DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
MutableInterval test = new MutableInterval(dt1, dt1);
assertEquals(dt1.getMillis(), test.getStartMillis());
assertEquals(dt1.getMillis(), test.getEndMillis());
}
public void testConstructor_RI_RI7() throws Throwable {
DateTime dt1 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
DateTime dt2 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
try {
new MutableInterval(dt1, dt2);
fail();
} catch (IllegalArgumentException ex) {}
}
public void testConstructor_RI_RI8() throws Throwable {
DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0, GJChronology.getInstance());
DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
MutableInterval test = new MutableInterval(dt1, dt2);
assertEquals(dt1.getMillis(), test.getStartMillis());
assertEquals(dt2.getMillis(), test.getEndMillis());
assertEquals(GJChronology.getInstance(), test.getChronology());
}
public void testConstructor_RI_RI9() throws Throwable {
DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1, GJChronology.getInstance());
MutableInterval test = new MutableInterval(dt1, dt2);
assertEquals(dt1.getMillis(), test.getStartMillis());
assertEquals(dt2.getMillis(), test.getEndMillis());
assertEquals(ISOChronology.getInstance(), test.getChronology());
}
//-----------------------------------------------------------------------
public void testConstructor_RI_RP1() throws Throwable {
DateTime dt = new DateTime(TEST_TIME_NOW);
Period dur = new Period(0, 6, 0, 0, 1, 0, 0, 0);
long result = TEST_TIME_NOW;
result = ISOChronology.getInstance().months().add(result, 6);
result = ISOChronology.getInstance().hours().add(result, 1);
MutableInterval test = new MutableInterval(dt, dur);
assertEquals(dt.getMillis(), test.getStartMillis());
assertEquals(result, test.getEndMillis());
}
public void testConstructor_RI_RP2() throws Throwable {
Instant dt = new Instant(new DateTime(TEST_TIME_NOW));
Period dur = new Period(0, 6, 0, 3, 1, 0, 0, 0);
long result = TEST_TIME_NOW;
result = ISOChronology.getInstanceUTC().months().add(result, 6);
result = ISOChronology.getInstanceUTC().days().add(result, 3);
result = ISOChronology.getInstanceUTC().hours().add(result, 1);
MutableInterval test = new MutableInterval(dt, dur);
assertEquals(dt.getMillis(), test.getStartMillis());
assertEquals(result, test.getEndMillis());
}
public void testConstructor_RI_RP3() throws Throwable {
DateTime dt = new DateTime(TEST_TIME_NOW, ISOChronology.getInstanceUTC());
Period dur = new Period(0, 6, 0, 3, 1, 0, 0, 0, PeriodType.standard());
long result = TEST_TIME_NOW;
result = ISOChronology.getInstanceUTC().months().add(result, 6);
result = ISOChronology.getInstanceUTC().days().add(result, 3);
result = ISOChronology.getInstanceUTC().hours().add(result, 1);
MutableInterval test = new MutableInterval(dt, dur);
assertEquals(dt.getMillis(), test.getStartMillis());
assertEquals(result, test.getEndMillis());
}
public void testConstructor_RI_RP4() throws Throwable {
DateTime dt = new DateTime(TEST_TIME_NOW);
Period dur = new Period(1 * DateTimeConstants.MILLIS_PER_HOUR + 23L);
long result = TEST_TIME_NOW;
result = ISOChronology.getInstance().hours().add(result, 1);
result = ISOChronology.getInstance().millis().add(result, 23);
MutableInterval test = new MutableInterval(dt, dur);
assertEquals(dt.getMillis(), test.getStartMillis());
assertEquals(result, test.getEndMillis());
}
public void testConstructor_RI_RP5() throws Throwable {
MutableInterval test = new MutableInterval((ReadableInstant) null, (ReadablePeriod) null);
assertEquals(TEST_TIME_NOW, test.getStartMillis());
assertEquals(TEST_TIME_NOW, test.getEndMillis());
}
public void testConstructor_RI_RP6() throws Throwable {
DateTime dt = new DateTime(TEST_TIME_NOW);
MutableInterval test = new MutableInterval(dt, (ReadablePeriod) null);
assertEquals(dt.getMillis(), test.getStartMillis());
assertEquals(dt.getMillis(), test.getEndMillis());
}
public void testConstructor_RI_RP7() throws Throwable {
Period dur = new Period(0, 6, 0, 0, 1, 0, 0, 0);
long result = TEST_TIME_NOW;
result = ISOChronology.getInstance().monthOfYear().add(result, 6);
result = ISOChronology.getInstance().hourOfDay().add(result, 1);
MutableInterval test = new MutableInterval((ReadableInstant) null, dur);
assertEquals(TEST_TIME_NOW, test.getStartMillis());
assertEquals(result, test.getEndMillis());
}
public void testConstructor_RI_RP8() throws Throwable {
DateTime dt = new DateTime(TEST_TIME_NOW);
Period dur = new Period(0, 0, 0, 0, 0, 0, 0, -1);
try {
new MutableInterval(dt, dur);
fail();
} catch (IllegalArgumentException ex) {}
}
//-----------------------------------------------------------------------
public void testConstructor_RP_RI1() throws Throwable {
DateTime dt = new DateTime(TEST_TIME_NOW);
Period dur = new Period(0, 6, 0, 0, 1, 0, 0, 0);
long result = TEST_TIME_NOW;
result = ISOChronology.getInstance().months().add(result, -6);
result = ISOChronology.getInstance().hours().add(result, -1);
MutableInterval test = new MutableInterval(dur, dt);
assertEquals(result, test.getStartMillis());
assertEquals(dt.getMillis(), test.getEndMillis());
}
public void testConstructor_RP_RI2() throws Throwable {
Instant dt = new Instant(new DateTime(TEST_TIME_NOW));
Period dur = new Period(0, 6, 0, 3, 1, 0, 0, 0);
long result = TEST_TIME_NOW;
result = ISOChronology.getInstanceUTC().months().add(result, -6);
result = ISOChronology.getInstanceUTC().days().add(result, -3);
result = ISOChronology.getInstanceUTC().hours().add(result, -1);
MutableInterval test = new MutableInterval(dur, dt);
assertEquals(result, test.getStartMillis());
assertEquals(dt.getMillis(), test.getEndMillis());
}
public void testConstructor_RP_RI3() throws Throwable {
DateTime dt = new DateTime(TEST_TIME_NOW, ISOChronology.getInstanceUTC());
Period dur = new Period(0, 6, 0, 3, 1, 0, 0, 0, PeriodType.standard());
long result = TEST_TIME_NOW;
result = ISOChronology.getInstanceUTC().months().add(result, -6);
result = ISOChronology.getInstanceUTC().days().add(result, -3);
result = ISOChronology.getInstanceUTC().hours().add(result, -1);
MutableInterval test = new MutableInterval(dur, dt);
assertEquals(result, test.getStartMillis());
assertEquals(dt.getMillis(), test.getEndMillis());
}
public void testConstructor_RP_RI4() throws Throwable {
DateTime dt = new DateTime(TEST_TIME_NOW);
Period dur = new Period(1 * DateTimeConstants.MILLIS_PER_HOUR + 23L);
long result = TEST_TIME_NOW;
result = ISOChronology.getInstance().hours().add(result, -1);
result = ISOChronology.getInstance().millis().add(result, -23);
MutableInterval test = new MutableInterval(dur, dt);
assertEquals(result, test.getStartMillis());
assertEquals(dt.getMillis(), test.getEndMillis());
}
public void testConstructor_RP_RI5() throws Throwable {
MutableInterval test = new MutableInterval((ReadablePeriod) null, (ReadableInstant) null);
assertEquals(TEST_TIME_NOW, test.getStartMillis());
assertEquals(TEST_TIME_NOW, test.getEndMillis());
}
public void testConstructor_RP_RI6() throws Throwable {
DateTime dt = new DateTime(TEST_TIME_NOW);
MutableInterval test = new MutableInterval((ReadablePeriod) null, dt);
assertEquals(dt.getMillis(), test.getStartMillis());
assertEquals(dt.getMillis(), test.getEndMillis());
}
public void testConstructor_RP_RI7() throws Throwable {
Period dur = new Period(0, 6, 0, 0, 1, 0, 0, 0);
long result = TEST_TIME_NOW;
result = ISOChronology.getInstance().monthOfYear().add(result, -6);
result = ISOChronology.getInstance().hourOfDay().add(result, -1);
MutableInterval test = new MutableInterval(dur, (ReadableInstant) null);
assertEquals(result, test.getStartMillis());
assertEquals(TEST_TIME_NOW, test.getEndMillis());
}
public void testConstructor_RP_RI8() throws Throwable {
DateTime dt = new DateTime(TEST_TIME_NOW);
Period dur = new Period(0, 0, 0, 0, 0, 0, 0, -1);
try {
new MutableInterval(dur, dt);
fail();
} catch (IllegalArgumentException ex) {}
}
//-----------------------------------------------------------------------
public void testConstructor_RI_RD1() throws Throwable {
long result = TEST_TIME_NOW;
result = ISOChronology.getInstance().months().add(result, 6);
result = ISOChronology.getInstance().hours().add(result, 1);
DateTime dt = new DateTime(TEST_TIME_NOW);
Duration dur = new Duration(result - TEST_TIME_NOW);
MutableInterval test = new MutableInterval(dt, dur);
assertEquals(dt.getMillis(), test.getStartMillis());
assertEquals(result, test.getEndMillis());
}
public void testConstructor_RI_RD2() throws Throwable {
MutableInterval test = new MutableInterval((ReadableInstant) null, (ReadableDuration) null);
assertEquals(TEST_TIME_NOW, test.getStartMillis());
assertEquals(TEST_TIME_NOW, test.getEndMillis());
}
public void testConstructor_RI_RD3() throws Throwable {
DateTime dt = new DateTime(TEST_TIME_NOW);
MutableInterval test = new MutableInterval(dt, (ReadableDuration) null);
assertEquals(dt.getMillis(), test.getStartMillis());
assertEquals(dt.getMillis(), test.getEndMillis());
}
public void testConstructor_RI_RD4() throws Throwable {
long result = TEST_TIME_NOW;
result = ISOChronology.getInstance().monthOfYear().add(result, 6);
result = ISOChronology.getInstance().hourOfDay().add(result, 1);
Duration dur = new Duration(result - TEST_TIME_NOW);
MutableInterval test = new MutableInterval((ReadableInstant) null, dur);
assertEquals(TEST_TIME_NOW, test.getStartMillis());
assertEquals(result, test.getEndMillis());
}
public void testConstructor_RI_RD5() throws Throwable {
DateTime dt = new DateTime(TEST_TIME_NOW);
Duration dur = new Duration(-1);
try {
new MutableInterval(dt, dur);
fail();
} catch (IllegalArgumentException ex) {}
}
//-----------------------------------------------------------------------
public void testConstructor_RD_RI1() throws Throwable {
long result = TEST_TIME_NOW;
result = ISOChronology.getInstance().months().add(result, -6);
result = ISOChronology.getInstance().hours().add(result, -1);
DateTime dt = new DateTime(TEST_TIME_NOW);
Duration dur = new Duration(TEST_TIME_NOW - result);
MutableInterval test = new MutableInterval(dur, dt);
assertEquals(result, test.getStartMillis());
assertEquals(dt.getMillis(), test.getEndMillis());
}
public void testConstructor_RD_RI2() throws Throwable {
MutableInterval test = new MutableInterval((ReadableDuration) null, (ReadableInstant) null);
assertEquals(TEST_TIME_NOW, test.getStartMillis());
assertEquals(TEST_TIME_NOW, test.getEndMillis());
}
public void testConstructor_RD_RI3() throws Throwable {
DateTime dt = new DateTime(TEST_TIME_NOW);
MutableInterval test = new MutableInterval((ReadableDuration) null, dt);
assertEquals(dt.getMillis(), test.getStartMillis());
assertEquals(dt.getMillis(), test.getEndMillis());
}
public void testConstructor_RD_RI4() throws Throwable {
long result = TEST_TIME_NOW;
result = ISOChronology.getInstance().monthOfYear().add(result, -6);
result = ISOChronology.getInstance().hourOfDay().add(result, -1);
Duration dur = new Duration(TEST_TIME_NOW - result);
MutableInterval test = new MutableInterval(dur, (ReadableInstant) null);
assertEquals(result, test.getStartMillis());
assertEquals(TEST_TIME_NOW, test.getEndMillis());
}
public void testConstructor_RD_RI5() throws Throwable {
DateTime dt = new DateTime(TEST_TIME_NOW);
Duration dur = new Duration(-1);
try {
new MutableInterval(dur, dt);
fail();
} catch (IllegalArgumentException ex) {}
}
//-----------------------------------------------------------------------
public void testConstructor_Object1() throws Throwable {
DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
MutableInterval test = new MutableInterval(dt1.toString() + '/' + dt2.toString());
assertEquals(dt1.getMillis(), test.getStartMillis());
assertEquals(dt2.getMillis(), test.getEndMillis());
}
public void testConstructor_Object2() throws Throwable {
DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
MutableInterval base = new MutableInterval(dt1, dt2);
MutableInterval test = new MutableInterval(base);
assertEquals(dt1.getMillis(), test.getStartMillis());
assertEquals(dt2.getMillis(), test.getEndMillis());
}
public void testConstructor_Object3() throws Throwable {
DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
Interval base = new Interval(dt1, dt2);
MutableInterval test = new MutableInterval(base);
assertEquals(dt1.getMillis(), test.getStartMillis());
assertEquals(dt2.getMillis(), test.getEndMillis());
}
public void testConstructor_Object4() throws Throwable {
MockInterval base = new MockInterval();
MutableInterval test = new MutableInterval(base);
assertEquals(base.getStartMillis(), test.getStartMillis());
assertEquals(base.getEndMillis(), test.getEndMillis());
}
public void testConstructor_Object5() throws Throwable {
IntervalConverter oldConv = ConverterManager.getInstance().getIntervalConverter("");
IntervalConverter conv = new IntervalConverter() {
public boolean isReadableInterval(Object object, Chronology chrono) {
return false;
}
public void setInto(ReadWritableInterval interval, Object object, Chronology chrono) {
interval.setChronology(chrono);
interval.setInterval(1234L, 5678L);
}
public Class<?> getSupportedType() {
return String.class;
}
};
try {
ConverterManager.getInstance().addIntervalConverter(conv);
DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
MutableInterval test = new MutableInterval(dt1.toString() + '/' + dt2.toString());
assertEquals(1234L, test.getStartMillis());
assertEquals(5678L, test.getEndMillis());
} finally {
ConverterManager.getInstance().addIntervalConverter(oldConv);
}
}
public void testConstructor_Object6() throws Throwable {
IntervalConverter oldConv = ConverterManager.getInstance().getIntervalConverter(new MutableInterval(0L, 0L));
IntervalConverter conv = new IntervalConverter() {
public boolean isReadableInterval(Object object, Chronology chrono) {
return false;
}
public void setInto(ReadWritableInterval interval, Object object, Chronology chrono) {
interval.setChronology(chrono);
interval.setInterval(1234L, 5678L);
}
public Class<?> getSupportedType() {
return ReadableInterval.class;
}
};
try {
ConverterManager.getInstance().addIntervalConverter(conv);
Interval base = new Interval(-1000L, 1000L);
MutableInterval test = new MutableInterval(base);
assertEquals(1234L, test.getStartMillis());
assertEquals(5678L, test.getEndMillis());
} finally {
ConverterManager.getInstance().addIntervalConverter(oldConv);
}
}
class MockInterval implements ReadableInterval {
public Chronology getChronology() {
return ISOChronology.getInstance();
}
public long getStartMillis() {
return 1234L;
}
public DateTime getStart() {
return new DateTime(1234L);
}
public long getEndMillis() {
return 5678L;
}
public DateTime getEnd() {
return new DateTime(5678L);
}
public long toDurationMillis() {
return (5678L - 1234L);
}
public Duration toDuration() {
return new Duration(5678L - 1234L);
}
public boolean contains(long millisInstant) {
return false;
}
public boolean containsNow() {
return false;
}
public boolean contains(ReadableInstant instant) {
return false;
}
public boolean contains(ReadableInterval interval) {
return false;
}
public boolean overlaps(ReadableInterval interval) {
return false;
}
public boolean isBefore(ReadableInstant instant) {
return false;
}
public boolean isBefore(ReadableInterval interval) {
return false;
}
public boolean isAfter(ReadableInstant instant) {
return false;
}
public boolean isAfter(ReadableInterval interval) {
return false;
}
public Interval toInterval() {
return null;
}
public MutableInterval toMutableInterval() {
return null;
}
public Period toPeriod() {
return null;
}
public Period toPeriod(PeriodType type) {
return null;
}
}
//-----------------------------------------------------------------------
public void testConstructor_Object_Chronology1() throws Throwable {
DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
Interval base = new Interval(dt1, dt2);
MutableInterval test = new MutableInterval(base, BuddhistChronology.getInstance());
assertEquals(dt1.getMillis(), test.getStartMillis());
assertEquals(dt2.getMillis(), test.getEndMillis());
assertEquals(BuddhistChronology.getInstance(), test.getChronology());
}
public void testConstructor_Object_Chronology2() throws Throwable {
DateTime dt1 = new DateTime(2004, 6, 9, 0, 0, 0, 0);
DateTime dt2 = new DateTime(2005, 7, 10, 1, 1, 1, 1);
Interval base = new Interval(dt1, dt2);
MutableInterval test = new MutableInterval(base, null);
assertEquals(dt1.getMillis(), test.getStartMillis());
assertEquals(dt2.getMillis(), test.getEndMillis());
assertEquals(ISOChronology.getInstance(), test.getChronology());
}
}